<?php

namespace App\Controller\Web;

use App\Base\BaseController4Web;
use App\Model\ArtCategoryModel;
use App\Model\ArtModel;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;

class FilesController extends BaseController4Web
{
    /**
     * @route("/file/item",name="WebFileItem")
     */
    public function WebFileItem(){
        $this->initData();
        return $this->render("Web/file_item.html.twig", $this->data);
    }
    /**
     * @route("/file/info",name="WebFileInfo")
     */
    public function WebFileInfo(){
        $this->initData();
        if (!$id = $this->getParamRequired("id")) {$id = 0;}
        $ArtModel = new ArtModel($this->getDoctrine());
        $art = $ArtModel->getById($id);
        $art->setScan($art->getScan()+1);
        $this->myEm()->persist($art);$this->myEm()->flush();
        
        if (!$art) {
            $art = $ArtModel->getRep()->findOneBy(array());
        }
        $ArtCategoryModel = new ArtCategoryModel($this->getDoctrine());
        $cat = $ArtCategoryModel->getById($art->getCategory());

        $this->data["headTab"] = strtolower($cat->getLink());

        $ArtModel = new ArtModel($this->getDoctrine());
        $data = $ArtModel->getCatListData($cat->getId(),0,1);
        $this->data["data"] = $data;
        $this->data["page"] = $this->creatPage($this->generateUrl("articleCatList",["id"=>$cat->getId()]),$data["total"],10);
//        $this->data["keywords"] = $keywords;
        $this->data["art"] = $art;



        return $this->render("Web/file_info.html.twig", $this->data);
    }

}
